//
//  YZMHIStoryTableViewCell.m
//  YZMicroStock
//
//  Created by apple on 16/11/2.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMHIStoryTableViewCell.h"
#import "NSNumber+Utils.h"

@interface YZMHIStoryTableViewCell()
@property(nonatomic,strong) UILabel *numberLabel;
@property(nonatomic,strong) UILabel *timeLabel;
@property(nonatomic,strong) UILabel *allMoney;
@property(nonatomic,strong) UILabel *ensureMoney;
@property(nonatomic,strong) UILabel *deferMoney;
@property(nonatomic,strong) UILabel *togetherMoney;
@property(nonatomic,strong) UILabel *haltMoney;

@end

@implementation YZMHIStoryTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createObject];
        self.backgroundColor = [YZMAppStyle colorForMain];
    }
    return self;
}

-(void)createObject
{
    self.numberLabel=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_numberLabel];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(19);
        make.top.mas_equalTo(self).offset(13);
        make.width.mas_equalTo(ScreenWidth*0.2);
    }];
    UIImageView *arrowImageView=[[UIImageView alloc]init];
    [arrowImageView setImage:[UIImage imageNamed:@"historyarrow"]];
    [self addSubview:arrowImageView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(7);
        make.height.mas_equalTo(13);
        make.right.mas_equalTo(self).offset(-15);
        make.centerY.equalTo(self.numberLabel);
    }];
    
    self.timeLabel=[YZMAppStyle labelWithMediumGray];
    [self addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.numberLabel);
        make.height.mas_equalTo(14);
        make.right.mas_equalTo(arrowImageView.mas_left).offset(-15);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    line1.backgroundColor=[YZMAppStyle colorForSplitLine];
    [self addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_numberLabel.mas_bottom).offset(13);
        make.width.mas_equalTo(self);
    }];

    UIView *line2=[YZMAppStyle splitLine];
    line2.backgroundColor=[YZMAppStyle colorForSplitLine];
    [self addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1.mas_bottom).offset(70);
        make.width.mas_equalTo(self);
    }];
    
    UIView *line3=[YZMAppStyle splitLine];
    line3.backgroundColor=[YZMAppStyle colorForSplitLine];
    [self addSubview:line3];
    [line3 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(146);
    }];
    
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1);
        make.left.mas_equalTo(self).offset((ScreenWidth-3)/3);
        make.width.mas_equalTo(0.5);
    }];
    
    UIView *line4=[YZMAppStyle splitLine];
    line4.backgroundColor=[YZMAppStyle colorForSplitLine];
    [self addSubview:line4];
    [line4 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(145);
    }];
    
    [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1);
        make.right.mas_equalTo(self.mas_right).offset(-(ScreenWidth-3)/3);
        make.width.mas_equalTo(0.5);
    }];
    
    UILabel *allMoneyLabel=[YZMAppStyle labelWithSmallGray];
    allMoneyLabel.text=@"总点买金额(元)";
    [self addSubview:allMoneyLabel];
    allMoneyLabel.textAlignment=NSTextAlignmentCenter;
    [allMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1).offset(20);
        make.left.mas_equalTo(self);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    self.allMoney=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_allMoney];
    _allMoney.textAlignment=NSTextAlignmentCenter;
    [_allMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(allMoneyLabel).offset(20);
        make.centerX.equalTo(allMoneyLabel);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    UILabel *ensureMoneyLabel=[YZMAppStyle labelWithSmallGray];
    ensureMoneyLabel.text=@"履约保证金(元)";
    [self addSubview:ensureMoneyLabel];
    ensureMoneyLabel.textAlignment=NSTextAlignmentCenter;
    [ensureMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(allMoneyLabel);
        make.left.mas_equalTo(line3);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];

    self.ensureMoney=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_ensureMoney];
    _ensureMoney.textAlignment=NSTextAlignmentCenter;
    [_ensureMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_allMoney);
        make.centerX.equalTo(ensureMoneyLabel);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];

    
    UILabel *deferMoneyLabel=[YZMAppStyle labelWithSmallGray];
    deferMoneyLabel.text=@"递延费(元)";
    [self addSubview:deferMoneyLabel];
    deferMoneyLabel.textAlignment=NSTextAlignmentCenter;
    [deferMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(allMoneyLabel);
        make.left.mas_equalTo(line4);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    self.deferMoney=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_deferMoney];
    _deferMoney.textAlignment=NSTextAlignmentCenter;
    [_deferMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_allMoney);
        make.centerX.equalTo(deferMoneyLabel);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    UILabel *togetherMoneyLabel=[YZMAppStyle labelWithSmallGray];
    togetherMoneyLabel.text=@"总交易综合费(元)";
    togetherMoneyLabel.adjustsFontSizeToFitWidth=YES;
    [self addSubview:togetherMoneyLabel];
    togetherMoneyLabel.textAlignment=NSTextAlignmentCenter;
    [togetherMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(allMoneyLabel);
        make.top.mas_equalTo(line2).offset(20);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    self.togetherMoney=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_togetherMoney];
    _togetherMoney.textAlignment=NSTextAlignmentCenter;
    [_togetherMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(togetherMoneyLabel);
        make.top.mas_equalTo(togetherMoneyLabel).offset(20);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    
    UILabel *haltMoneyLabel=[YZMAppStyle labelWithSmallGray];
    haltMoneyLabel.text=@"结算盈亏";
    [self addSubview:haltMoneyLabel];
    haltMoneyLabel.textAlignment=NSTextAlignmentCenter;
    [haltMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_ensureMoney);
        make.centerY.equalTo(togetherMoneyLabel);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
    
    self.haltMoney=[YZMAppStyle labelWithMediumWhite];
    [self addSubview:_haltMoney];
    _haltMoney.textColor=[YZMAppStyle colorForGrayText];
    _haltMoney.textAlignment=NSTextAlignmentCenter;
    [_haltMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(haltMoneyLabel);
        make.centerY.equalTo(_togetherMoney);
        make.width.mas_equalTo(ScreenWidth*0.33);
    }];
}

-(void)setModel:(YZMHistoryModel *)model
{
    _model=model;
    _numberLabel.text=[NSString stringWithFormat:@"%@",@(model.Id)];
    _timeLabel.text=[NSString stringWithFormat:@"已操盘%@天",@(model.hadHoldDays)];
    _allMoney.text=[NSString stringWithFormat:@"%@",@(model.money).r2fString];
    _ensureMoney.text=[NSString stringWithFormat:@"%@",@(model.lossPrincipal).r2fString];
    _deferMoney.text=[NSString stringWithFormat:@"%@",@(model.deferCharge).r2fString];
    _togetherMoney.text=[NSString stringWithFormat:@"%@",@(model.serviceCharge).r2fString];
    _haltMoney.text=[NSString stringWithFormat:@"%@",@(model.profitShare).r2fString];
    if ([@(model.profitShare) isGreaterThanDouble:0]) {
        _haltMoney.text=[NSString stringWithFormat:@"+%@",@(model.profitShare).r2fString];
        _haltMoney.textColor=[YZMAppStyle colorForRiseText];
    }else if(![@(model.profitShare) isEqualGreaterThanDouble:0]){
        _haltMoney.textColor=[YZMAppStyle colorForDropText];
    }else{
        _haltMoney.textColor=[YZMAppStyle colorForGrayText];
    }
}

//if (myModel.currentProfit) {
//    
//    myMoneyLabel.text=[NSString stringWithFormat:@"%@",@([myModel.currentProfit doubleValue]).r2fString];
//    if ([@([myModel.currentProfit doubleValue]) isGreaterThanDouble:0]) {
//        
//        myMoneyLabel.textColor=[YZMAppStyle colorForRedText];
//    }else if (![@([myModel.currentProfit doubleValue]) isGreaterThanDouble:0]) {
//        
//        myMoneyLabel.textColor=[YZMAppStyle colorForGreenText];
//    }else if ([@([myModel.currentProfit doubleValue]) isGreaterThanDouble:0]){
//        
//        myMoneyLabel.textColor=[YZMAppStyle colorForWhite];
//    }


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
